Imports Clo = Enhancements.Core.Logging
Imports Ere = Enhancements.Basic.RegularExpressions
Imports Glo = System.Globalization
Imports Iou = System.IO
Imports Ref = System.Reflection
Imports Reg = System.Text.RegularExpressions
Imports Sys = System
Imports Tex = System.Text
Imports Xsd = System.Xml.Schema
Imports W3c = System.Xml

Namespace Enhancements.Basic.Expressions
    ''' <summary>Represents a token extracted from an expression.</summary>
    <Serializable(), DebuggerStepThrough()> _
    Public MustInherit Class Token

        Friend Sub New(ByVal _expression As System.String, ByVal _expressionBeginIndex As Sys.Int32, ByVal _expressionEndIndex As Sys.Int32)
            Expression = _expression
            ExpressionBeginIndex = _expressionBeginIndex
            ExpressionEndIndex = _expressionEndIndex
        End Sub

        Private __Expression As System.String = Nothing
        ''' <summary>The expression from where the token was extracted.</summary>
        ''' <exception cref="IsEmptyException">_value is equal to System.String.Empty.</exception>
        ''' <exception cref="IsNullException">_value is null.</exception>
        Public Property Expression() As System.String
            Get
                Return __Expression
            End Get
            Private Set(ByVal _value As System.String)
                _value.IsEmptyNot("Expression._value", True)

                __Expression = _value
            End Set
        End Property

        Private __ExpressionBeginIndex As Sys.Int32 = 0
        ''' <summary>The token begin index in the expression.</summary>
        ''' <exception cref="IsInRangeNotException">_value is lower than 0 or higher than Expression.Length - 1.</exception>
        Public Property ExpressionBeginIndex() As Sys.Int32
            Get
                Return __ExpressionBeginIndex
            End Get
            Private Set(ByVal _value As Sys.Int32)
                _value.IsInRange("ExpressionBeginIndex._value", 0, Expression.Length - 1, True)

                __ExpressionBeginIndex = _value
            End Set
        End Property

        Private __ExpressionEndIndex As Sys.Int32 = 0
        ''' <summary>The token end index in the expression.</summary>
        ''' <exception cref="IsInRangeNotException">_value is lower than ExpressionBeginIndex or higher than Expression.Length - 1.</exception>
        Public Property ExpressionEndIndex() As Sys.Int32
            Get
                Return __ExpressionEndIndex
            End Get
            Private Set(ByVal _value As Sys.Int32)
                _value.IsInRange("ExpressionEndIndex._value", ExpressionBeginIndex, Expression.Length - 1, True)

                __ExpressionEndIndex = _value
            End Set
        End Property

        ''' <summary>The token as is represented in the expression.</summary>
        Public ReadOnly Property ExpressionPart() As System.String
            Get
                Return Expression.Substring(ExpressionBeginIndex, ExpressionEndIndex - ExpressionBeginIndex + 1)
            End Get
        End Property

        ''' <summary>Determines the token's correct representation for use in an expression.</summary>
        ''' <returns> </returns>
        Public MustOverride Function ToRepresentation() As System.String

    End Class
End Namespace
